Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
¿Por qué la variable "cambiar" obtiene resultados extraños?

por qué la función no funciona, bastante sencillo, el cambio debe llegar a 0.
Supongo que será otra forma más eficiente de resolver este problema, pero lo que me molesta es el hecho de que "cambiar" obtiene números extraños... ayuda.

 function checkCashRegister(price, cash, cid) { var change= cash-price var money={ 'PENNY':0.01, 'NICKEL':0.05, 'DIME':0.1, 'QUARTER':0.25, 'ONE':1, 'FIVE':5, 'TEN':10, 'TWENTY':20, 'ONE HUNDRED':100} console.log(change,'start') let i=8; while(change>0){ // console.log(cid[i][1]) if(change<cid[i][1]&&change>money[cid[i][0]]){ console.log(cid[i][0], 'cid') console.log(money[cid[i][0]],'money') change=change-money[cid[i][0]] console.log(change, 'change') i=8; } i-- } } checkCashRegister(19.4, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

JS guarda un valor flotante como datos binarios, por lo que su 19.4 no será exactamente 19.4 . Por eso 20 - 19.4 no es exactamente 0.6 .

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!